//
//  DSFriendsRecommendDetailTabCell.m
//  budejie
//
//  Created by tangQiang on 8/27/16.
//  Copyright © 2016 Dason. All rights reserved.
//

#import "DSFriendsRecommendDetailTabCell.h"
#import "DSFriendsRecommendDetailModel.h"
#import "UIImageView+WebCache.h"

@interface DSFriendsRecommendDetailTabCell ()
/**
 *  附件 Button
 */
@property (strong, nonatomic) UIButton *accessoryBtn;

/**
 *  图标
 */
@property (strong, nonatomic) UIImageView *headerImageView;

/**
 *  昵称
 */
@property (strong, nonatomic) UILabel *screen_nameLabel;

/**
 *  粉丝数
 */
@property (strong, nonatomic) UILabel *fans_countLabel;

/**
 *  分割线
 */
@property (strong, nonatomic) UIImageView *separetorImageView;

/**
 *  vip
 */
@property (strong, nonatomic) UIImageView *vipImageView;



@end
@implementation DSFriendsRecommendDetailTabCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        // 添加子控件
        [self.contentView addSubview:self.accessoryBtn];
        [self.contentView addSubview:self.headerImageView];
        [self.contentView addSubview:self.screen_nameLabel];
        [self.contentView addSubview:self.fans_countLabel];
        [self.contentView addSubview:self.separetorImageView];
        [self.contentView addSubview:self.vipImageView];
    }
    
    return self;
}

#pragma mark - 懒加载Button

// 附件
- (UIButton *)accessoryBtn {
    if (_accessoryBtn == nil) {
        UIButton *accessoryBtn = [[UIButton alloc]init];
        _accessoryBtn = accessoryBtn;
        [_accessoryBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
        [_accessoryBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        _accessoryBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_accessoryBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    }
    return _accessoryBtn;
}

// 图标
- (UIImageView *)headerImageView {
    if (_headerImageView == nil) {
        _headerImageView = [[UIImageView alloc]init];
        _headerImageView.layer.cornerRadius = 20;
        _headerImageView.layer.masksToBounds = YES;
    }
    return _headerImageView;
}

// 昵称
- (UILabel *)screen_nameLabel {
    if (_screen_nameLabel == nil) {
        _screen_nameLabel = [[UILabel alloc]init];
        _screen_nameLabel.font = [UIFont systemFontOfSize:14];
    }
    return _screen_nameLabel;
}

// 粉丝数
- (UILabel *)fans_countLabel {
    if (_fans_countLabel == nil) {
        _fans_countLabel = [[UILabel alloc]init];
        _fans_countLabel.textColor = [UIColor grayColor];
        _fans_countLabel.font = [UIFont systemFontOfSize:12];
    }
    return _fans_countLabel;
}

// 分割线
- (UIImageView *)separetorImageView {
    if (_separetorImageView == nil) {
        _separetorImageView = [[UIImageView alloc]init];
    }
    return _separetorImageView;
}

// vip
- (UIImageView *)vipImageView {
    if (_vipImageView == nil) {
        _vipImageView = [[UIImageView alloc]init];
    }
    return _vipImageView;
}

#pragma mark - 布局子控件
- (void)layoutSubviews {
    // 附件
    [self.accessoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
        make.width.equalTo(@(60));
        make.height.equalTo(@(30));
    }];
    
    // 图标
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(10);
        make.width.height.equalTo(@(40));
    }];

    // 昵称
    [self.screen_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImageView.mas_right).offset(8);
        make.top.equalTo(self.headerImageView.mas_top);
    }];

    // 粉丝数
    [self.fans_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImageView.mas_right).offset(8);
        make.bottom.equalTo(self.headerImageView.mas_bottom);
    }];

    // 底线
    [self.separetorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(@(0));
        make.height.equalTo(@(0.5));
    }];
    
    // vipImageview
    [self.vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.screen_nameLabel);
        make.left.equalTo(self.screen_nameLabel.mas_right).offset(8);
        make.width.height.equalTo(@(15));
    }];
}


- (void)click {
    NSLog(@"点击了订阅");
}

#pragma mark - set 方法重写
- (void)setFriendsRecommendDetailModel:(DSFriendsRecommendDetailModel *)friendsRecommendDetailModel {
    _friendsRecommendDetailModel = friendsRecommendDetailModel;
    // 设置图标
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:friendsRecommendDetailModel.header] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    
    // 设置昵称
    self.screen_nameLabel.text = friendsRecommendDetailModel.screen_name;
    if (friendsRecommendDetailModel.is_vip) {
        self.vipImageView.image = [UIImage imageNamed:@"header_cry_icon"];
        self.screen_nameLabel.textColor = [UIColor redColor];
    } else {
        self.vipImageView.image = nil;
        self.screen_nameLabel.textColor = [UIColor blackColor];
    }
    
    // 设置粉丝数
    self.fans_countLabel.text = [NSString stringWithFormat:@"%@关注", friendsRecommendDetailModel.fans_count];

    
    // 设置分割线
    self.separetorImageView.image = [UIImage imageNamed:@"cell-content-line"];
}

@end
